/*
 * $Id: LogEventSearchCriteria.java 15 2014-08-17 14:20:24Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws6.system.vo;

import java.io.Serializable;
import java.util.Date;

import javax.inject.Named;

import org.omnifaces.cdi.ViewScoped;

import cn.ratking.demo.jaws6.common.DateUtils;

/**
 * 系统日志查询条件
 */
@Named
@ViewScoped
public class LogEventSearchCriteria implements Serializable {

    private Long logEventId;
    private String userId;
    private String userName;
    private String description;
    private Date beginDate;
    private Date endDate;

    /** 无参构造方法 */
    public LogEventSearchCriteria() {
    }

    public Long getLogEventId() {
        return logEventId;
    }

    public void setLogEventId(Long logEventId) {
        this.logEventId = logEventId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * 检查调整查询条件中的开始与结束时间
     */
    public void checkDate() {
        // 检查并确保startDateBegin在startDateEnd之前，并调整其时分秒
        if (beginDate != null && endDate != null && beginDate.after(endDate)) {
            Date tmpDate = beginDate;
            beginDate = endDate;
            endDate = tmpDate;
        }
        if (beginDate != null) {
            beginDate = DateUtils.getBeginDate(beginDate);
        }
        if (endDate != null) {
            endDate = DateUtils.getEndDate(endDate);
        }
    }

    /**
     * 返回测试字符串
     *
     * @return 测试字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("[LogEventSearchCriteria: logEventId=").append(logEventId);
        sb.append(", userId=").append(userId);
        sb.append(", userName=").append(userName);
        sb.append(", description=").append(description);
        sb.append(", beginDate=").append(beginDate);
        sb.append(", endDate=").append(endDate);
        sb.append("]");

        return sb.toString();
    }
}
